import random
from time import sleep


# 求最长回文

def radom_str():
    keys = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    return ''.join(random.choices(keys, k=random.randint(100, 1000)))


def check_max_long_huiwen_str(long_str):
    results = []
    num = len(long_str)
    number = 0
    for i in range(0, num):
        for j in range(i, num + 1):
            temp_str = long_str[i:j]

            if temp_str == temp_str[::-1]:
                temp_num = len(temp_str)
                if temp_num > number:
                    number = temp_num
                    results = [temp_str]
                    # print("results1：{}".format(results))
                elif temp_num == number:
                    results.append(temp_str)
                    # print("results2：{}".format(results))
                else:
                    pass  # 不是最长的回文
            else:
                pass  # 不是回文
    return " ".join(results)


while True:
    ins = input("请输入要生成字符串的个数(q退出)：")
    if ins == 'q':
        print("程序已退出")
        break
    elif ins.isdigit():
        ins_int = int(ins)
        for _ in range(ins_int):
            result = radom_str()
            sleep(0.3)
            print("随机字符串：{}".format(result))
            huiwen_str = check_max_long_huiwen_str(result)
            print("最长回文字符串：{}".format(huiwen_str))
    else:
        print("输入格式有误，请重新输入")
